<template>
  <div class="main">
    <el-container>
      <el-header>
        <div class="logo"></div>
        <h3>宙斯健身房</h3>
        <div class="header-actions">
          <el-button type="danger" @click="logout">退出登录</el-button>
        </div>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <!--侧面导航栏-->
          <el-menu default-active="/main" router :unique-opened="true">
            <template v-for="mi in menuItems">
              <el-sub-menu v-if="Array.isArray(mi.children)" :index="mi.name">
                <template #title>
                  <span>{{ mi.name }}</span>
                </template>
                <el-menu-item v-for="smi in mi.children" :index="smi.url">
                  <span>{{ smi.name }}</span>
                </el-menu-item>
              </el-sub-menu>
              <el-menu-item v-else :index="mi.url">
                <span>{{ mi.name }}</span>
              </el-menu-item>
            </template>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view>

          </router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<style scoped>
.main {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.el-container {
  height: 100%;
}

.el-header {
  display: flex;
  align-items: center;
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
  color: white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  padding: 0 20px;
}

.el-header h3 {
  margin: 0;
  margin-left: 15px;
  font-size: 1.5rem;
  font-weight: 500;
  flex: 1;
}

header > .logo {
  height: 50px;
  width: 50px;
  background: url("@/assets/gymLogo.png") no-repeat center center/cover;
  border-radius: 4px;
}

.header-actions {
  display: flex;
  align-items: center;
}

.el-aside {
  background-color: #f8f9fa;
  border-right: 1px solid #e6e6e6;
}

.el-menu {
  border-right: none;
  background-color: transparent;
}

.el-menu-item,
.el-sub-menu__title {
  color: #333;
  transition: all 0.3s;
}

.el-menu-item:hover,
.el-sub-menu__title:hover {
  background-color: #e9f5ff;
  color: #1e3c72;
}

.el-menu-item.is-active {
  background-color: #e1edff;
  color: #1e3c72;
  font-weight: 500;
}

.el-main {
  padding: 20px;
  background-color: #f5f7fa;
}

.el-sub-menu .el-menu-item {
  min-width: auto;
}
</style>


<script setup>
import {reactive} from "vue";
import {removeJwt} from "@/api/jwt.js";
import {useRouter} from "vue-router";

const router = useRouter();

const menuItems = reactive([{
  name: "仪表盘",
  url: "/main/chart"
}, {
  name: "用户管理",
  children: [{
    name: "会员管理",
    url: "/main/member"
  }, {
    name: "教练管理",
    url: "/main/coach"
  }, {
    name: "管理员账户",
    url: "/main/admin"
  }]
}, {
  name: "课程运营 ",
  children: [{
    name: "课程管理",
    url: "/main/course"
  }, {
    name: "预约管理",
    url: "/main/reserve"
  }
  //todo: 添加教室资源管理
/*  , {
    name: "教室资源",
    url: "/main/class"
  }*/
  ]
}])

const logout = () => {
  removeJwt();
  router.push("/login");
}
</script>

